From f32797d3310d8eb1851b07249f5270f1be1ae39a Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Fri, 3 Dec 2010 09:36:47 +0000 Subject: [PATCH] libxc: osdep: convert xc_map_foreign_{batch,bulk} Signed-off-by: Ian Campbell Signed-off-by: Ian Jackson --- tools/libxc/Makefile | 1 + tools/libxc/xc_foreign_memory.c | 35 +++++++++++++++++++++++++++++++++ tools/libxc/xc_linux.c | 35 ++++++++++++++++++++------------- tools/libxc/xc_minios.c | 13 ++++++++---- tools/libxc/xc_misc.c | 9 +++------ tools/libxc/xc_netbsd.c | 11 ++++++++--- tools/libxc/xc_solaris.c | 13 ++++++++---- tools/libxc/xenctrlosdep.h | 10 ++++++++++ 8 files changed, 96 insertions(+), 31 deletions(-) create mode 100644 tools/libxc/xc_foreign_memory.c diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile index 1852408497..ff23f30c58 100644 --- a/tools/libxc/Makefile +++ b/tools/libxc/Makefile @@ -30,6 +30,7 @@ CTRL_SRCS-y += xc_mem_event.c CTRL_SRCS-y += xc_mem_paging.c CTRL_SRCS-y += xc_memshr.c CTRL_SRCS-y += xc_hcall_buf.c +CTRL_SRCS-y += xc_foreign_memory.c CTRL_SRCS-y += xtl_core.c CTRL_SRCS-y += xtl_logger_stdio.c CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c diff --git a/tools/libxc/xc_foreign_memory.c b/tools/libxc/xc_foreign_memory.c new file mode 100644 index 0000000000..953f63bbaf --- /dev/null +++ b/tools/libxc/xc_foreign_memory.c @@ -0,0 +1,35 @@ +/****************************************************************************** + * xc_foreign_memory.c + * + * Functions for mapping foreign domain's memory. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "xc_private.h" + +void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, + xen_pfn_t *arr, int num ) +{ + return xch->ops->u.privcmd.map_foreign_batch(xch, xch->ops_handle, + dom, prot, arr, num); +} + +void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot, + const xen_pfn_t *arr, int *err, unsigned int num) +{ + return xch->ops->u.privcmd.map_foreign_bulk(xch, xch->ops_handle, + dom, prot, arr, err, num); +} diff --git a/tools/libxc/xc_linux.c b/tools/libxc/xc_linux.c index a0539cd0b5..76d4791845 100644 --- a/tools/libxc/xc_linux.c +++ b/tools/libxc/xc_linux.c @@ -81,7 +81,7 @@ static int linux_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall); } -static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom, +static int xc_map_foreign_batch_single(int fd, uint32_t dom, xen_pfn_t *mfn, unsigned long addr) { privcmd_mmapbatch_t ioctlx; @@ -96,21 +96,23 @@ static int xc_map_foreign_batch_single(xc_interface *xch, uint32_t dom, { *mfn ^= XEN_DOMCTL_PFINFO_PAGEDTAB; usleep(100); - rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); + rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); } while ( (rc < 0) && (errno == ENOENT) ); return rc; } -void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, - xen_pfn_t *arr, int num) +static void *linux_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, int prot, + xen_pfn_t *arr, int num) { + int fd = (int)h; privcmd_mmapbatch_t ioctlx; void *addr; int rc; - addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, xch->fd, 0); + addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, fd, 0); if ( addr == MAP_FAILED ) { PERROR("xc_map_foreign_batch: mmap failed"); @@ -122,7 +124,7 @@ void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, ioctlx.addr = (unsigned long)addr; ioctlx.arr = arr; - rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); + rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); if ( (rc < 0) && (errno == ENOENT) ) { int i; @@ -133,7 +135,7 @@ void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, XEN_DOMCTL_PFINFO_PAGEDTAB ) { unsigned long paged_addr = (unsigned long)addr + (i << PAGE_SHIFT); - rc = xc_map_foreign_batch_single(xch, dom, &arr[i], + rc = xc_map_foreign_batch_single(fd, dom, &arr[i], paged_addr); if ( rc < 0 ) goto out; @@ -154,16 +156,18 @@ void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, return addr; } -void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot, - const xen_pfn_t *arr, int *err, unsigned int num) +static void *linux_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, int prot, + const xen_pfn_t *arr, int *err, unsigned int num) { + int fd = (int)h; privcmd_mmapbatch_v2_t ioctlx; void *addr; unsigned int i; int rc; addr = mmap(NULL, (unsigned long)num << PAGE_SHIFT, prot, MAP_SHARED, - xch->fd, 0); + fd, 0); if ( addr == MAP_FAILED ) { PERROR("xc_map_foreign_batch: mmap failed"); @@ -176,7 +180,7 @@ void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot, ioctlx.arr = arr; ioctlx.err = err; - rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx); + rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx); if ( rc < 0 && errno == ENOENT ) { @@ -192,7 +196,7 @@ void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot, ioctlx.err = err + i; do { usleep(100); - rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx); + rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH_V2, &ioctlx); } while ( rc < 0 && err[i] == -ENOENT ); } } @@ -216,7 +220,7 @@ void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot, ioctlx.addr = (unsigned long)addr; ioctlx.arr = pfn; - rc = ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); + rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx); rc = rc < 0 ? -errno : 0; @@ -236,7 +240,7 @@ void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot, err[i] = rc ?: -EINVAL; continue; } - rc = xc_map_foreign_batch_single(xch, dom, pfn + i, + rc = xc_map_foreign_batch_single(fd, dom, pfn + i, (unsigned long)addr + ((unsigned long)i<retval; } -void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, - xen_pfn_t *arr, int num) +static void *netbsd_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, int prot, + xen_pfn_t *arr, int num) { + int fd = (int)h; privcmd_mmapbatch_t ioctlx; void *addr; addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_ANON | MAP_SHARED, -1, 0); @@ -94,7 +96,7 @@ void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, ioctlx.dom=dom; ioctlx.addr=(unsigned long)addr; ioctlx.arr=arr; - if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 ) + if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 ) { int saved_errno = errno; PERROR("xc_map_foreign_batch: ioctl failed"); @@ -178,6 +180,9 @@ static struct xc_osdep_ops netbsd_privcmd_ops = { .u.privcmd = { .hypercall = &netbsd_privcmd_hypercall; + + .map_foreign_batch = &netbsd_privcmd_map_foreign_batch, + .map_foreign_bulk = &xc_map_foreign_bulk_compat, }, }; diff --git a/tools/libxc/xc_solaris.c b/tools/libxc/xc_solaris.c index cdcc2222c4..8152868e7c 100644 --- a/tools/libxc/xc_solaris.c +++ b/tools/libxc/xc_solaris.c @@ -74,12 +74,14 @@ static int solaris_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privc return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall); } -void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, - xen_pfn_t *arr, int num) +static void *solaris_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, int prot, + xen_pfn_t *arr, int num) { + int fd = (int)h; privcmd_mmapbatch_t ioctlx; void *addr; - addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xch->fd, 0); + addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, fd, 0); if ( addr == MAP_FAILED ) return NULL; @@ -87,7 +89,7 @@ void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot, ioctlx.dom=dom; ioctlx.addr=(unsigned long)addr; ioctlx.arr=arr; - if ( ioctl(xch->fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 ) + if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 ) { int saved_errno = errno; PERROR("XXXXXXXX"); @@ -168,6 +170,9 @@ static struct xc_osdep_ops solaris_privcmd_ops = { .u.privcmd = { .hypercall = &solaris_privcmd_hypercall; + + .map_foreign_batch = &solaris_privcmd_map_foreign_batch, + .map_foreign_bulk = &xc_map_foreign_bulk_compat, }, }; diff --git a/tools/libxc/xenctrlosdep.h b/tools/libxc/xenctrlosdep.h index 59928fb7b7..204b9e87e9 100644 --- a/tools/libxc/xenctrlosdep.h +++ b/tools/libxc/xenctrlosdep.h @@ -63,6 +63,11 @@ struct xc_osdep_ops union { struct { int (*hypercall)(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall); + + void *(*map_foreign_batch)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot, + xen_pfn_t *arr, int num); + void *(*map_foreign_bulk)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot, + const xen_pfn_t *arr, int *err, unsigned int num); } privcmd; } u; }; @@ -83,6 +88,11 @@ typedef struct xc_osdep_info xc_osdep_info_t; /* All backends, including the builtin backend, must supply this structure. */ extern xc_osdep_info_t xc_osdep_info; +/* Stub for not yet converted OSes */ +void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h, + uint32_t dom, int prot, + const xen_pfn_t *arr, int *err, unsigned int num); + #endif /* -- 2.30.2